package com.selangshiwo.sina.biz;

import java.util.Map;
import com.selangshiwo.Util;
import com.selangshiwo.sina.httpclient.SinaHttpClient;
import com.selangshiwo.sina.requst.WeiboLoginRequestPack;
import com.selangshiwo.sina.result.ResultPack;
import com.selangshiwo.sina.result.WeiboLoginResultPack;

public class WeiboLoginBiz implements IBaseHttpBiz{

	private String url = "";
	private Map<String , String> userinfo = null ;
	private boolean isSuc = false ;
	
	public WeiboLoginBiz(String url ){
		this.url = url ;
	}
	
	public Map<String , String> getUserInfo(){
		return this.userinfo ;
	}
	
	public boolean isLoginSuccess(){
		return this.isSuc ;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public ResultPack run() {
		Util.debug("*登录认证+++++++++++++++++++");
		WeiboLoginRequestPack request = new WeiboLoginRequestPack(this.url);
		Util.debug("*开始处理业务....");
		WeiboLoginResultPack result = (WeiboLoginResultPack)SinaHttpClient.getInstance().getRequest(request, WeiboLoginResultPack.class);
		Map<String , ?> resultJson = (Map<String, ?>) Util.string2map(Util.getParams(result.getContext(), 0));
		if((Boolean)resultJson.get("result") == true){
			this.userinfo = (Map<String , String>)resultJson.get("userinfo");
			this.isSuc = true ;
		}else{
			Util.err("*****登录失败**************");
			//稍后从此抛出异常
		}
		
		return result ;
	}

}
